package com.twb.auth.entity.twbResource;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.twb.core.base.entity.BaseEntity;
import org.apache.ibatis.type.JdbcType;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 资源信息
 * </p>
 *
 * @author DSY
 * @since 2018-10-24
 */
@TableName(value = "TWB_RESOURCE")
public class TwbResource extends BaseEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 编号
	 */
	@TableId(value="id",type=IdType.INPUT)
	private String id;

	/**
	 * 父级编码
	 */
	@TableField(value="parent_res_id",jdbcType = JdbcType.VARCHAR)
	private String parentResId;

	/**
	 * 资源名称
	 */
	@TableField(value="name",jdbcType = JdbcType.VARCHAR)
	private String name;

	/**
	 * 资源路径
	 */
	@TableField(value="url",jdbcType = JdbcType.VARCHAR)
	private String url;

	/**
	 * 资源类型
	 */
	@TableField(value="res_type",jdbcType = JdbcType.VARCHAR)
	private String resType;

	/**
	 * 资源图标
	 */
	@TableField(value="icon_cls",jdbcType = JdbcType.VARCHAR)
	private String iconCls;

	/**
	 * 顺序
	 */
	@TableField(value="res_seq",jdbcType = JdbcType.INTEGER)
	private Integer resSeq;

	/**
	 * 目标（1:主窗口；2:新窗口）
	 */
	@TableField(value="target",jdbcType = JdbcType.VARCHAR)
	private String target;

	/**
	 * 主窗口打开模式（1：单页模式；2：ifream模式）
	 */
	@TableField(value="OPEN_TYPE",jdbcType = JdbcType.VARCHAR)
	private String openType;
	
	/**
	 * 资源描述
	 */
	@TableField(value="description",jdbcType = JdbcType.VARCHAR)
	private String description;

	/**
	 * 资源状态
	 */
	@TableField(value="status",jdbcType = JdbcType.VARCHAR)
	private String status;

	/**
	 * 是否记录日志
	 */
	@TableField(value="islog",jdbcType = JdbcType.INTEGER)
	private String islog;
	
	/** 是否缓存（0-否，1-是） */
    @TableField(value="iscache",jdbcType = JdbcType.INTEGER)
	private String iscache;
	
	/** 项目ID */
    @TableField(value="project_id",jdbcType = JdbcType.VARCHAR)
	private String projectId;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getParentResId() {
		return parentResId;
	}

	public void setParentResId(String parentResId) {
		this.parentResId = parentResId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getResType() {
		return resType;
	}

	public void setResType(String resType) {
		this.resType = resType;
	}

	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	public Integer getResSeq() {
		return resSeq;
	}

	public void setResSeq(Integer resSeq) {
		this.resSeq = resSeq;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getOpenType() {
		return openType;
	}

	public void setOpenType(String openType) {
		this.openType = openType;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getIslog() {
		return islog;
	}

	public void setIslog(String islog) {
		this.islog = islog;
	}

	/** 是否缓存（0-否，1-是） */
	public String getIscache() {
		return iscache;
	}
	/** 是否缓存（0-否，1-是） */
	public void setIscache(String iscache) {
		this.iscache = iscache;
	}
	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

	@Override
	public String toString() {
		return "TwbResource{" + "id=" + id + ", parentResId=" + parentResId + ", name=" + name + ", url=" + url
				+ ", resType=" + resType + ", iconCls=" + iconCls + ", resSeq=" + resSeq + ", target=" + target
				+ ", description=" + description + ", status=" + status + ", projectId=" + projectId + ", islog="
				+ islog + ", creatorId=" + creatorId + ", creator=" + creator + ", updaterId=" + updaterId
				+ ", updater=" + updater + ", createDate=" + createDate + ", updateDate=" + updateDate + ", isdel="
				+ isdel + "}";
	}

	/**
	 * @Title sort
	 * @Class Twresource.java
	 * @Package com.tw.sys.model
	 * @Description 根据序号排序
	 * 
	 * @param twresources
	 * 
	 * @author DSY
	 * @date 2014年9月21日 下午5:04:10
	 */
	public void sort(List<TwbResource> twresources) {
		Collections.sort(twresources, new Comparator<TwbResource>() {// 排序
			@Override
			public int compare(TwbResource o1, TwbResource o2) {
				if (o1.getResSeq() == null) {
					o1.setResSeq(10000);
				}
				if (o2.getResSeq() == null) {
					o2.setResSeq(10000);
				}
				return o1.getResSeq().compareTo(o2.getResSeq());
			}
		});
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		
		if (obj == null || getClass() != obj.getClass()) {
			return false;
		}
		
		TwbResource resource = (TwbResource) obj;
		
		return Objects.equals(id, resource.getId());
	}
}
